package ar.com.niktutos.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Order;

import ar.com.niktutos.dao.TagDAO;
import ar.com.niktutos.dto.TagDTO;

public class TagDAOImpl extends AbstractGenericDAOImpl<TagDTO,Integer> implements TagDAO{

	public TagDTO findByDescripcion(String descript) {
	   	 Session sess = sessionFactory.openSession();
		 Transaction tx = null;
		 TagDTO retorna = null;
		 try {
		     tx = sess.beginTransaction();
	         Query query = sess.createQuery("from TagDTO t where t.descripcion like ?");
		     query.setString(0, descript);
		     List<TagDTO> lista = query.list();
		     if(lista != null && lista.size() > 0)
		    	 retorna = (TagDTO) lista.get(0);
		     tx.commit();
		 }
		 catch (Exception e) {
		     if (tx!=null) tx.rollback();
		     e.printStackTrace();
		 }
		 finally {
		     sess.close();
		 }
		 return retorna;
	}

}
